import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

def get_dataset(data_file):
    with open(data_file,'r') as in_file:
        txt = in_file.readlines()#将数据集以字符串列表的形式放在txt里面['1.2 3 4\n','1 2]
        txt = [txt[i].split(' ') for i in range(len(txt))]#将字符串txt[i](['1.2 3 4\n','1 2 3\n'])转化为[['1.2','2','3','\n'],['1','2','3','\n']]
        txt = [x.strip() for i in range(len(txt)) for x in txt[i] if x.strip() != '']
        for i in range(len(txt)):
            txt[i] = float(txt[i])
    return txt

d = 'output.txt'
out = np.array(get_dataset(d))
x_begin = out[0] 
x_end = out[1]
y_begin = out[2]
y_end = out[3]
order = out[6]
h_x = int(order * out[4] + 1)
h_y = int(order * out[5] + 1)
u = out[7:]

figure = plt.figure()
ax = Axes3D(figure)
X = np.linspace(x_begin, x_end, h_x)
Y = np.linspace(y_begin, y_end, h_y)
X, Y = np.meshgrid(X, Y)
Z = u.reshape(h_y, h_x) 
ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1, cmap = 'rainbow') 
plt.show()
